﻿using AFanDa.BLL.BLLService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AFanDa.Admin.Controllers
{
    public class OrderController : Controller
    {



        OrderService _orderService = null;

        public OrderController()
        {
            _orderService = new OrderService();
        }


        /// <summary>
        /// 订单页面
        /// </summary>
        /// <returns></returns>
        public ActionResult OrderHtml()
        {
            return View();
        }


        // GET: Order
        /// <summary>
        /// 点单页面
        /// </summary>
        /// <returns></returns>
        public ActionResult BuyOrderHtml()
        {
            return View();
        }

        /// <summary>
        /// 订单支付页面
        /// </summary>
        /// <returns></returns>
        public ActionResult OrderPay()
        {
            return View();
        }

        /// <summary>
        /// 添加订单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult CreateOrder(Dto.Request.OrderRequestDto dto)
        {

            var result = _orderService.CreateOrder(dto);
            return Json(result);

        }

        /// <summary>
        /// 获取订单信息
        /// </summary>
        /// <param name="oid"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetOrderInfo(string oid)
        {

            var result = _orderService.GetOrderInfo(new Dto.Request.OrderRequestDto()
            {
                id = oid
            });

            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 修改订单状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult UpdateOrderState(string oid, int state)
        {
            var result = _orderService.UpdateOrderState(new Dto.Request.OrderRequestDto()
            {
                id = oid
                ,
                state = state
            });

            return Json(result);
        }







        /// <summary>
        /// 获取所有订单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetALLOrder(string key = "", int state = -1, int limit = 10, int page = 1)
        {

            var result = _orderService.GetALLOrder(new Dto.Request.OrderRequestDto()
            {
                key = key,
                limit = limit,
                page = page,
                state = state
            });
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 订单详情页面
        /// </summary>
        /// <returns></returns>
        public ActionResult OrderDetails()
        {
            return View();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult PayOK(Dto.Request.OrderRequestDto dto)
        {
            var result = _orderService.PayOK(dto);
            return Json(result);
        }



        /// <summary>
        /// 获取所有订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetALlDetails(string id)
        {

            var reuslt = _orderService.GetALlDetails(new Dto.Request.OrderRequestDto()
            {
                id = id
            });

            return Json(reuslt, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 获取支付详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetAllPay(string id)
        {

            var reuslt = _orderService.GetAllPay(new Dto.Request.OrderRequestDto()
            {
                id = id
            });

            return Json(reuslt, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 支付详情页面
        /// </summary>
        /// <returns></returns>
        public ActionResult PayHtml()
        {
            return View();
        }
    }
}